IMPACT AIT
Visual Basic 6.0 Edition


 

Return to Index
  ›HTTP Client - VB6 - Light Bulb Inspection

Access inspection data from an IMPACT vision device through an HTTP interface

Notes: The default AIT root distribution folder for this application is: /Datalogic/IMPACT/AIT/HTTP Client/
If the image does not display in the program window after you click Update, be sure the file association for PNG files is the Windows default.

Configure the IMPACT vision device
Create the Visual Basic program
Trigger the vision device
Display the vision device data

Configure the IMPACT vision device

1.       Start VPM and select the Settings tab.

2.       Select the File Manager, then select the Setup tab.

3.       Copy the file named Light Bulb Inspection.vp from the AIT distribution subfolder /VisualBasic6/Example1/IMPACT Files and paste it into the folder /IMPACT Root/VisionPrograms

4.       Load the file named Light Bulb Inspection.vp.

5.       Click the File Camera/Live Camera button to select File Camera mode.

6.       Add, and make Active, the images named Bulb1.png through Bulb10.png from the AIT distribution subfolder /VisualBasic6/Example1/IMPACT Files.

7.       Leave VPM open.

Create the Visual Basic program

1.       Start Microsoft Visual Basic 6.0.
(Note: This sample code is in the AIT distribution subfolder /VisualBasic6/Example1/Project.)

2.       Select a new Standard EXE project type and click OK. See Example

3.       In the project explorer dialog, select Project1 and press F4.

4.       In the project properties dialog, change the project name to http_access. See Example

5.       Press Ctrl-T to show the component selection dialog box.

6.       On the Controls tab, select Microsoft Internet Controls and Microsoft Internet Transfer Control 6.0 and click OK. See Example
(Note: If no controls are listed, be sure the "Selected Items Only" checkbox is unchecked.)

7.       From the Project pull down menu select References.

8.       Select Microsoft XML, v3.0 and click OK. See Example

9.       Add a Web Browser control to the form and change the name to imageBrowser. See Example

10.    Add a timer control to the form and change the name getDataTimer. Change the interval to 2000.

11.    Add three command buttons to the form. Change the button names and captions as follows:
Command1 - Name = update; Caption = Update
Command2 - Name = resetCounts; Caption = Reset Counts
Command3 - Name = snapCamera; Caption = Snap Camera

12.    Add an Inet control to the form and change the name to sendCommand. See Example

13.    Add two textboxes to the form.

14.    Change the name of text1 to IPAddress and change the text property to your IMPACT device's IP address.

15.    Change the name of text2 to rateTime and change the text property to 2000.

16.    Add a shape control to the form and change the name to dataAccess. Change the shape property to 3 - Circle, the FillStyle property to 0 - Solid, and the Height property to 255.

17.    Add eight label controls to the form.

18.    Change the name of label1 to runCounts and the caption to Run:

19.    Change the name of label2 to runCounts. When the question dialog "Do you want to create a control array?" is displayed, click Yes.

20.    Clear the caption property of the control "runCounts(1) in the label array.

21.    Repeat steps 18 through 20 for each of the following sets of controls, but substitute the name and caption properties shown for each pair of label controls you add to the form. (Clear the caption property of the second control in the array in each case.) When you have finished you will have two labels in each array, for example runCounts(0) and runCounts(1).
Label3 - Name = passCounts; Caption = Pass:
Label4 - Name = passCounts; Caption = " "
Label5 - Name = failCounts; Caption = Fail:
Label6 - Name = failCounts; Caption = " "
Label7 - Name = leadLength; Caption = Lead Length
Label8 - Name = leadLength; Caption = " "

22.    Double click on the Form and enter the following code. (You may select and copy the code from this page, then paste it into the form.)

Option Explicit
Dim urlStr As String
Dim systemStat As Boolean
Private xmlDoc(0 To 10) As DOMDocument
Private Sub Load_Image()
'this will display the processed image in the webbrowser control
imageBrowser.Navigate ("http://" & IPAddress.Text & "/getData/Light Bulb Inspection.Inspect Bulb:Image")

End Sub
Private Sub Form_Load()
getDataTimer.Interval = rateTime.Text
imageBrowser.Navigate ("about:blank")
End Sub

Private Sub getDataTimer_Timer()

On Error GoTo Errorhandler

If dataAccess.FillColor = &HC0C0C0 Then
dataAccess.FillColor = vbGreen
Else
dataAccess.FillColor = &HC0C0C0
End If

If imageBrowser.Busy <> True Then
Load_Image
End If

Dim result As Double
Dim xmlChildNode As IXMLDOMNode
Dim objNodeList(0 To 10) As IXMLDOMNodeList

Set xmlDoc(0) = New DOMDocument
Set xmlDoc(1) = New DOMDocument
Set xmlDoc(2) = New DOMDocument
Set xmlDoc(3) = New DOMDocument

'Parse Run Counts
xmlDoc(0).async = False
xmlDoc(0).Load ("http://" & IPAddress.Text & "/getData/Light Bulb Inspection.Inspect Bulb.Inspection Counts:runcounts")

'Parse Pass Counts
xmlDoc(1).async = False
xmlDoc(1).Load ("http://" & IPAddress.Text & "/getData/Light Bulb Inspection.Inspect Bulb.Inspection Counts:passcounts")

'Parse Fail Counts
xmlDoc(2).async = False
xmlDoc(2).Load ("http://" & IPAddress.Text & "/getData/Light Bulb Inspection.Inspect Bulb.Inspection Counts:failcounts")

'Parse Lead Length Measurement
xmlDoc(3).async = False
xmlDoc(3).Load ("http://" & IPAddress.Text & "/getData/Light Bulb Inspection.Inspect Bulb.Measure Lead:Distance List")

'Format and Display Run Counts
Set objNodeList(0) = xmlDoc(0).getElementsByTagName("val")
result = objNodeList(0).Item(0).Text
runCounts(1).Caption = result

'Format and Display Pass Counts
Set objNodeList(1) = xmlDoc(1).getElementsByTagName("val")
result = objNodeList(1).Item(0).Text
passCounts(1).Caption = result

'Format and Display Fail Counts
Set objNodeList(2) = xmlDoc(2).getElementsByTagName("val")
result = objNodeList(2).Item(0).Text
failCounts(1).Caption = result

'Format and Display Lead Length Measurement Result
Set objNodeList(3) = xmlDoc(3).getElementsByTagName("MList0")
result = objNodeList(3).Item(0).Text
leadLength(1).Caption = Round(result, 2)

Exit Sub

Errorhandler:
getDataTimer.Enabled = False
update.Caption = "Update"
MsgBox "Unable To Access Data, Check for valid IP Address and Data Links", vbCritical

End Sub

Private Sub rateTime_Change()
getDataTimer.Interval = rateTime.Text
End Sub

Private Sub resetCounts_Click()

'this will reset the counts on the IMPACT
If sendCommand.StillExecuting <> True Then
sendCommand.url = "http://" & IPAddress.Text & "/run/Light Bulb Inspection.Reset Counts"
sendCommand.Execute
Do Until sendCommand.StillExecuting <> True
DoEvents
Loop
getDataTimer_Timer
End If

End Sub

Private Sub snapCamera_Click()

'this will acquire a new image and process it through the inspection task
If sendCommand.StillExecuting <> True Then
sendCommand.url = "http://" & IPAddress.Text & "/run/Light Bulb Inspection.Snap Camera"
sendCommand.Execute
Do Until sendCommand.StillExecuting <> True
DoEvents
Loop
getDataTimer_Timer
End If
End Sub

Private Sub update_Click()

If update.Caption = "Update" Then
getDataTimer.Enabled = True
update.Caption = "Stop Update"
snapCamera.Enabled = False
Else
getDataTimer.Enabled = False
update.Caption = "Update"
snapCamera.Enabled = True
End If
End Sub

23.    Save the project.

24.    Make an executable file from the project then run the executable. What does the program User Interface look like?

Trigger the vision device

1.       Using IMPACT VPM, connect to your IMPACT Device.

2.       Select the Settings tab.

3.       Select the General icon. (In IMPACT versions prior to 9.0, select the System System Object.)

4.       Click the Trigger Events radio button.

5.       In Software Triggering, set the Continuous Triggers value to 2000.

6.       Click Start Triggers.

7.       The vision device will run the vision program every 2000 milliseconds.

Display the vision device data

1.       In the Visual Basic program, click the Update button.

2.       The program will query the vision device and display the inspection data in the program window every 2000 milliseconds (the value in the Rate field). The Shape Control will blink each time the display updates. When you click the Stop Update button, the update will stop.


©2003-2013 Datalogic Automation Inc. All Rights Reserved